class Greeter{
    greeting : string;//greeting的属性
    constructor(message : string ){//一个构造函数
        this.greeting = message;//this。 它表示我们访问的是类的成员。
    }
    greet():string{//greet方法
        return 'hello '+ this.greeting;
    }
}

let greering = new Greeter('world');
// console.log(greering.greet());

class Animal{
    name:string;
    constructor(theName:string){//如果构造函数声明protected 这个类不能在包含它的类外被实例化，但是能被继承
        this.name = theName;
    }
    move(dist:number = 0){
        console.log(`${this.name}跑了${dist} m`);
    }
}

class Snake extends Animal{
    constructor(name:string){
        super(name);//调用父类构造
    }
    move(dist:number = 5){//继承了父类并重写父类
        console.log(`重写父类`);
        super.move(dist);//调用父类的方法
    }
}
let skn = new Snake(`我在这里`);
// skn.move(20);

// 存取器
let passcode = "secret passcode";
class Employee {
    private _fullName: string;

    get fullName(): string {
        return this._fullName;
    }

    set fullName(newName: string) {
        if (passcode && passcode == "secret passcode") {
            this._fullName = newName;
        }
        else {
            console.log("Error: Unauthorized update of employee!");
        }
    }
}
let employee = new Employee();
employee.fullName = "Bob Smith";
// if (employee.fullName) {
//     alert(employee.fullName);
// }


// 静态属性
class Grid {
    static origin = {x: 0, y: 0};
    calculateDistanceFromOrigin(point: {x: number; y: number;}) {
        let xDist = (point.x - Grid.origin.x);
        let yDist = (point.y - Grid.origin.y);
        return Math.sqrt(xDist * xDist + yDist * yDist) / this.scale;
    }
    constructor (public scale: number) { }
}

let grid1 = new Grid(1.0);  // 1x scale
let grid2 = new Grid(5.0);  // 5x scale
// console.log(grid1.calculateDistanceFromOrigin({x: 10, y: 10}));
// console.log(grid2.calculateDistanceFromOrigin({x: 10, y: 10}));















